/* ---------------------------------------------------------------------------
** Client.cpp
** 	Send packages to robot via WIFI
**
** Author: Roel Postelmans
** -------------------------------------------------------------------------*/ 

#include "client.h"

void Client::init() {   
   sockfd=socket(AF_INET,SOCK_DGRAM,0);

   bzero(&servaddr_a,sizeof(servaddr_a));
   servaddr_a.sin_family = AF_INET;
   servaddr_a.sin_addr.s_addr=inet_addr(GROEP_A);
   servaddr_a.sin_port=htons(3200);

   bzero(&servaddr_b,sizeof(servaddr_b));
   servaddr_b.sin_family = AF_INET;
   servaddr_b.sin_addr.s_addr=inet_addr(GROEP_B);
   servaddr_b.sin_port=htons(3200);
}

void Client::send(Udp_package udp_package) {
   sendto(sockfd,&udp_package,sizeof(Udp_package),0, (struct sockaddr *)&servaddr_b,sizeof(servaddr_b));
   sendto(sockfd,&udp_package,sizeof(Udp_package),0, (struct sockaddr *)&servaddr_a,sizeof(servaddr_a));      
}

void Client::close_socket() {
   close(sockfd);
}
/* EXAMPLE USE*/
int main( int arc, char **argv ) {
   Client c;
   c.init();

   Info i;
   i.robx=200;
   i.roby=99;
   i.robhoek=45;
   i.doelx=3;
   i.doely=4;
   i.garx=9;
   i.gary=90;
   Udp_package udp;
   udp.info_b=i;
   c.send(udp);
   c.close_socket();
   return 0;

}

